package com.appjishu.web.controller;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.appjishu.passport.annotation.AuthController;
import com.appjishu.passport.annotation.RestrictAccess;
import com.appjishu.passport.intercepter.LoginInterceptor;
import com.appjishu.web.biz.service.GameLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.List;
import java.util.Map;
@Api(tags = "游戏")
@RequestMapping("game")
@RestController
@CrossOrigin
@AuthController
public class UserGameLogController {
    @Autowired
    private GameLogService gameLogService;

    @ApiOperation(value = "加分", notes = "游戏通关")
    @RestrictAccess(ttl = 10000, accessFrequency = 1)
    @PostMapping("/success")
    public void AddScore(Integer gameId){
        Long userId = LoginInterceptor.getUserId();
        gameLogService.gameLog(userId, gameId);
    }
    @ApiOperation(value = "通过表格加分", notes = "通过表格")
    @PostMapping("/successByExcel")
    private List<Map<String,Object>> readerExcelInfo(String excelUrl){
        ExcelReader excelReader = ExcelUtil.getReader(new File(excelUrl));
        List<Map<String, Object>> maps = excelReader.readAll();
        return maps;
    }
}
